<?php

/**
 * Copyright              [HD框架] (C)2011-2012 houdunwang ，Inc. 
 * Encoding               UTF-8 
 * Version                $Id: fields      2012-8-27 10:21:16
 * @author                向军
 * Link                   http://www.houdunwang.com       
 * E-mail                 houdunwangxj@gmail.com
 */
final class field {

    function __construct() {
        
    }

    /**
     * 获得表字段
     * @param type $mid
     * @return type 
     */
    public function get_all($mid) {
        $field = include "./data/field/field_" . $mid . ".php";
        foreach ($field as $k => $v) {
            $fieldSet = array();
            eval("\$fieldSet=" . $v['fieldset'] . ';');
            $field[$k]['fieldset'] = $fieldSet;
            $field[$k]['html'] = self::field_html($v);
        }
        return $field;
    }

    /**
     * 得到HTML中的表单
     * @param array $v
     * @return type 
     */
    public function field_html($field) {
        $fieldName = strstr($field['tablename'], "_data") ?
                $field['tablename'] . "[" . $field['fname'] . "]" : $field['fname'];
        $class = $field['fieldset']['css'];
        $validate = $field['validate'];
        $value = $field['fieldset']['value'];
        switch ($field['type']) {
            case "text":
                $type = (int) $field['fieldset']['ispassword'] ? "password" : "text";
                return "<input validate ='$validate' type='$type' name='$fieldName'
                value='$value'  class='$class'/>";
        }
    }

}

?>
